/*
https://leetcode.cn/problems/binary-tree-paths/
257. 二叉树的所有路径
*/
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<string> binaryTreePaths(TreeNode* root) {
        vector<string>res;
        if(root==NULL) return res;
        string s="";
        cal(root,res,s);
        return res;
    }
    void cal(TreeNode *root,vector<string>&res,string s){

        if(root->left!=NULL){
            cal(root->left,res,s+to_string(root->val)+"->");
        }
        if(root->right!=NULL){
            cal(root->right,res,s+to_string(root->val)+"->");
        }
        if(root->left==NULL&&root->right==NULL)
            res.push_back(s+to_string(root->val));
    }
};